package SingletonPattern;

public class Singleton {
  private Singleton(){};
  private static volatile Singleton instance;
  public static Singleton getInstance(){
    if(instance == null){
    	//利用同步代码块对当前类上锁
      synchronized(Singleton.class){
      	if(instance == null){
      		instance=new Singleton();
      	}
      }
    }
    return instance;
  }
}
